{include file="public/header"}
<link rel="stylesheet" href="__PUBLIC__/home/css/mobileSelect.css">
<body>
	<div class="sectionY">
		<a href="javascript:history.back();">
			<img src="__PUBLIC__/home/images/a19.png" alt="" class="a1">
		</a>
		<p class="p1">我的地址</p>
		<a href="javascript:;" onclick="delAddress('{$address.id}')" class="a3">删除</a>
	</div>
	<div class="kong1" style=""></div>
	<div class="add_dizhi">
		<form action="">
			<input type="hidden" name="address_id" value="{$address.id}">
			<input type="hidden" name="area_position" value="{$address.area_position}">
			<input type="hidden" name="pro_id" value="{$address.pro_id}">
			<input type="hidden" name="city_id" value="{$address.city_id}">
			<input type="hidden" name="area_id" value="{$address.area_id}">
			<div class="f1 clearfix">
				<span class="s1">联系人</span>
				<input type="text" name="name" value="{$address.name}" placeholder="真实姓名" class="input1">
			</div>
			<div class="f1 clearfix">
				<span class="s1">手机号</span>
				<input type="text" name="mobile" value="{$address.mobile}" placeholder="手机号" class="input1">
			</div>
			<div class="f1 clearfix">
				<span class="s1">所在地区</span>
				<img src="__PUBLIC__/home/images/a68.png" alt="" class="im1">
				<div class="lol">
					<div data-role="page" id="area2">
						{$address.procity}
					</div>
				</div>
			</div>
			<div class="f1 clearfix">
				<span class="s1">详细地址</span>
				<input type="text" name="address" value="{$address.address}" placeholder="详细地址" class="input1">
			</div>
			<div class="ge"></div>
			<div class="f2 clearfix">
				<span class="s2">设为默认地址</span>
				<input type="hidden" name="is_def" value="{$address.is_def}">
				<img src="__PUBLIC__/home/images/switch_on.png" alt="" class="im1 ud1" {if $address.is_def eq 1}style="display:none;" {else/}style="display:inline;" {/if}>
				<img src="__PUBLIC__/home/images/switch_off.png" alt="" class="im1 ud2" {if $address.is_def eq 0}style="display:none;" {else/}style="display:inline;" {/if}>
			</div>
			<div class="sub">
				<input type="button" value="保存" id="submit">
			</div>
		</form>
	</div>
</body>
<script src="__PUBLIC__/home/js/mobileSelect.js"></script>
<script>
	var redirect_url = "{$redirect_url}";
	$(function(){
		$(".ud1").click(function(){
			$(".ud2").show();
			$("input[name='is_def']").val(1);
			$(this).hide();
		})
		$(".ud2").click(function(){
			$(".ud1").show();
			$("input[name='is_def']").val(0);
			$(this).hide();
		})
		
		$("#submit").click(function () {
			let data = $("form").serialize();
			$.post("{:url('editAddress')}", data, function (res) {
				modal.msg(res.result_info);
				if(res.result_code==0){
					if(redirect_url != ""){
						location.replace("{:url('User/address')}?redirect_url="+redirect_url);
					}else{
						location.replace("{:url('User/address')}");
					}
				}
			});
		})
	})
	
	function delAddress(address_id) {
		modal.confirm("确定删除此收获地址？", "确定", function () {
			$.post("{:url('delAddress')}", {address_id:address_id}, function (res) {
				modal.msg(res.result_info);
				if(res.result_code == 0){
					if(redirect_url != ""){
						location.replace("{:url('User/address')}?redirect_url="+redirect_url);
					}else{
						location.replace("{:url('User/address')}");
					}
				}
			});
		})
		
	}
</script>
<script type="text/javascript">
	var mobileSelect3 = new MobileSelect({
		trigger: '#area2',
		title: '地区选择',
		wheels: [
			{
				data:{$region}
			}
		],
		position:"{$address.area_position}".split(","),
		callback:function(indexArr, data){
			$("input[name='area_position']").val(indexArr.join(","));
			$.each(data, function (i,v) {
				if(i==0){
					$("input[name='pro_id']").val(v.id);
				}
				if(i==1){
					$("input[name='city_id']").val(v.id);
				}
				if(i==2){
					$("input[name='area_id']").val(v.id);
				}
			})
		}
	});
</script>
</html>